<template>
    <el-card>
        <el-form :model="queryParams" ref="queryParams" :inline="true" label-width="100px">
            <el-form-item label="所属服务：" prop="serviceName">
                <el-input v-model="queryParams.serviceName" placeholder="所属服务" size="small"></el-input>
            </el-form-item>
            <el-form-item label="接口名：" prop="name">
                <el-input v-model="queryParams.name" placeholder="接口名" size="small"></el-input>
            </el-form-item>
             <el-form-item label="路径：" prop="path">
                <el-input v-model="queryParams.path" placeholder="路径" size="small"></el-input>
            </el-form-item>
             <el-form-item label="类型：" prop="opType">
                 <el-select v-model="queryParams.opType" placeholder="请选择" size="small">
                    <el-option v-for="item in statusArr" :label="item.label" :key="item.value" :value="item.value"></el-option>
                  </el-select>
            </el-form-item>
             <!-- <el-form-item label="操作时间：" prop="opTimeStart">
                <el-date-picker 
                    size="small"
                    type="datetime"
                    prop="queryParams.opTimeStart"
                    placeholder="开始日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item prop="opTimeEnd">
                -
                 <el-date-picker
                    size="small"
                    prop="queryParams.opTimeEnd"
                    type="datetime"
                    placeholder="结束日期">
                </el-date-picker>
            </el-form-item> -->
            <el-form-item >
                <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-delete" size="small" @click="resetQuery('queryParams')">清空</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="small">
            <el-table-column type="index" label="#" width="50"></el-table-column>
            <el-table-column label="所属服务" prop="serviceName"></el-table-column>
            <el-table-column label="接口名" prop="name"></el-table-column>
            <el-table-column label="方法" prop="method"></el-table-column>
            <el-table-column label="路径" prop="path"></el-table-column>
            <el-table-column label="操作人员" prop="opBy"></el-table-column>
            <el-table-column label="类型" prop="opType"></el-table-column>
            <el-table-column label="操作时间" prop="opTime" width="200"></el-table-column>
            <el-table-column label="版本号" prop="version"></el-table-column>
            <el-table-column label="操作" width="100" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
         <el-pagination
                v-show="total>0"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                :current-page="1"
                :page-sizes="[10, 20, 30, 40,50,100]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                class="pagination-container"
                :total="total">
        </el-pagination>
   </el-card>
</template>

<script>
import { getAggLogList } from '@/api/aggregate/log.api'
    export default {
        data() {
          return {
            queryParams: {
                current: 1,
                size: 10,
                serviceName: undefined,
                name: undefined,
                path: undefined,
                opType: undefined,
                opTimeStart: '',
                opTimeEnd: ''
            },
            tableData: [],
            statusArr: [
                {label: '新增',value: 0},
                {label: '修改',value: 1},
                {label: '发布',value: 2},
                {label: '下线',value: 3},
                {label: '回滚',value: 4},
                {label: '删除',value: 5},
            ],
            total: 0
          }
        },
        mounted() {
            this.getList();
        },
        filters: {
            statusFilter(value) {
                if(value===1) {
                    return '未发布';
                }
            }
        },
        methods: {
            async getList() {
                const result = await getAggLogList(this.queryParams);
                if(result.code === 200) {
                    this.tableData = result.data.records;
                    this.total = result.data.total
                }
            },
              // 搜索
            handleQuery() {
                this.queryParams.current = 1;
                this.getList();
            },
            // 清空
            resetQuery(formName) {
                this.$refs[formName].resetFields();
                this.getList();
            },
            handleSizeChange(val) {
                this.queryParams.size = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.queryParams.current = val;
                this.getList();
            },
        }
    }
</script>
<style lang="scss" scoped>
.pagination-container {
    padding: 10px;
    text-align: right;
}
</style>